<%@ page import="org.springframework.web.context.request.SessionScope" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%request.setAttribute("ctx", request.getContextPath());%>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui-v2.9.14/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/layui.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/layui_ext/xmSelect/xm-select.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/crypto-js.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/echarts.js"></script>
    <title>报表作业</title>
</head>
<body>

<form class="layui-form layui-row layui-col-space16">
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-username"></i>
            </div>
            <select name="sellType">
                <option value="">请选择</option>
            </select>
        </div>
    </div>

    <div class="layui-btn-container layui-col-xs12">
        <button class="layui-btn" lay-submit lay-filter="demo-table-search">Search</button>
        <button type="reset" class="layui-btn layui-btn-primary">Clear</button>
    </div>
</form>
<div id="main" style="width: 600px;height:400px;"></div>
<button class="layui-btn" lay-on="e1">导出excel</button>
<table class="layui-hide" id="ID-table-demo-search"></table>

<script>
    layui.use(function(){
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var $ = layui.$;
        var util = layui.util;
        //  2.9+ 版本可省略 attr 参数，默认读取 lay-on
        util.on({
            e1: function(){
            location.href="/file/exportExcel.do"
            },
        });
        $.post("/state/listSell.do",function (res){

            let data = res.data;

            for (let i = 0; i < data.length; i++) {
                $("select[name='sellType']").append("<option value='"+data[i].id+"'>"+data[i].sellName+"</option>")
            }
            form.render('select')
        })

        // 创建表格实例
        table.render({
            elem: '#ID-table-demo-search',
            url: '/state/list.do', // 此处为静态模拟数据，实际使用时需换成真实接口
            cols: [[
                {type: 'radio', title: '😊', fixed: true}, // 单选框
                {field:'id', title: 'ID', width:80, sort: true, fixed: true},
                {field:'createTime', title: '时间', width:180},
                {field:'balance', title: '余额', width:80, sort: true},
                {field:'sellName', title: '销售分类', width:100},
            ]],
            parseData:function (res) {
                return{
                    code:res.code,
                    data:res.data.list,
                    count:res.data.total,
                }
            },limit:3,
            page: true,
            height: 310
        });
        // 日期
        laydate.render({
            elem: '.demo-table-search-date'
        });
        // 搜索提交
        form.on('submit(demo-table-search)', function(data){
            var field = data.field; // 获得表单字段
            // 执行搜索重载
            table.reload('ID-table-demo-search', {
                page: {
                    curr: 1 // 重新从第 1 页开始
                },
                where: field // 搜索的字段
            });
            layer.msg('搜索成功');
            return false; // 阻止默认 form 跳转
        });
    });
</script>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));

    let createTime = [];//

    let balance = [];

    $.post("/state/listNew.do",function (res){

        let data = res.data;
        for (let i = 0; i < data.length; i++) {
            createTime.push(data[i].createTime)
            balance.push(data[i].balance)
        }
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '报表数据试看'
            },
            tooltip: {},
            legend: {
                data: ['时间']
            },
            xAxis: {
                data: createTime
            },
            yAxis: {},
            series: [
                {
                    name: '金额',
                    type: 'bar',
                    data: balance
                }
            ]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    })
</script>
</body>
</html>